package com.kawa.service.impl;


import cn.hutool.json.JSONUtil;
import com.kawa.constant.CommonConstants;
import com.kawa.entity.po.User;
import com.kawa.service.UserInfoService;
import com.kawa.util.RedisUtil;
import com.kawa.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private TokenUtil tokenUtil;

    @Override
    public User getUserInfo(String token) {
        try {
            if (tokenUtil.validateJwtToken(token)) {
                String freshToken =   redisUtil.get("Access_token:"+token);
                if (tokenUtil.validateJwtToken(freshToken)) {

                    String info = redisUtil.get("Refresh_token:"+freshToken);


                    return JSONUtil.toBean(info, User.class);

                } else {
                    return null;
                }
            } else {
                return null;
            }
        } catch (Exception e) {

            System.out.println(e);
            return null;
        }


    }
}
